import time
from selenium import webdriver
from selenium.webdriver.common.by import By

# 打开浏览器,请求网址
driver = webdriver.Chrome()
driver.get('https://mail.163.com/')

# 切换到frame
frame = driver.find_element(By.TAG_NAME, 'iframe')
driver.switch_to.frame(frame)


# 定位账号
username = driver.find_element(By.NAME, 'email').send_keys('fly291700430')

# 定位密码
password = driver.find_element(By.NAME, 'password').send_keys('********')

# 定位登录按钮
btn= driver.find_element(By.ID, 'dologin').click()

# 定位写信
time.sleep(2)
write_l = driver.find_element(By.XPATH, '//*[@id="_mail_component_149_149"]/span[2]').click()

# 定位收件人
driver.find_element(By.CLASS_NAME, 'nui-editableAddr-ipt').send_keys('291700430@qq.com')

# 定位主题
driver.find_element(By.XPATH, '//input[contains(@id,"subjectInput")]').send_keys('test')

# 定位正文,输入信息
editor_frame = driver.find_element(By.CLASS_NAME, 'APP-editor-iframe')
driver.switch_to.frame(editor_frame)

body = driver.find_element(By.TAG_NAME, 'body')
js = 'document.body.innerHTML="TEST1111"'
driver.execute_script(js)


# 定位发送,点击
driver.switch_to.parent_frame()
footer = driver.find_element(By.TAG_NAME, 'footer')
send_div = footer.find_element(By.TAG_NAME, 'div').click()

# 退出浏览器
time.sleep(2)
driver.quit()